//
//  ViewController.swift
//  BasicTools
//
//  Created by Ting Han on 2022/3/11.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        func block<T>(value: T,  closure: (T) -> Void) -> T{
            closure(value)
            return value
        }
        
        let red = block(value: UIView()) {
            $0.backgroundColor = .red
            $0.translatesAutoresizingMaskIntoConstraints = false
        }
       
        let green: UIView = {
            $0.backgroundColor = .green
            $0.translatesAutoresizingMaskIntoConstraints = false
           return $0
        }(UIView())
        
        view.addSubview(red)
        view.addSubview(green)
        
        red.leadingAnchor =*= view.leadingAnchor + 100
        red.topAnchor =*= view.topAnchor + 100
        red.widthAnchor =*= 250
        red.heightAnchor =*= 300
        green.topAnchor =*= red.bottomAnchor + 20
        green.centerXAnchor =*= red.centerXAnchor
        green.widthAnchor =*= red.widthAnchor/2
        green.heightAnchor =*= green.widthAnchor*2 - 50
      
        // test
        
        // test
        
    }


}

extension ViewController {
    override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
        super.traitCollectionDidChange(previousTraitCollection)
        
    }
}

